<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>批量使用正则完成密码验证</title>
  </head>
  <body>
    <input type="text" name="password" />
  </body>
  <script>
    const input = document.querySelector("[name='password']");
    input.addEventListener("keyup", (e) => {
      const value = e.target.value;
      //密码由字母数字构成，必须包含一个大写字母和一个数字
      const regs = [/^[0-9a-z]{5,10}$/i, /[A-Z]/, /[0-9]/];
      let state = regs.every((e) => e.test(value));
      console.log(state ? "密码正确" : "密码错误");
    });
  </script>
</html>
